package com.jial08.designpatterns.prototype.deep.clone;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>类描述：clone 实现对象深复制，对象也要实现 clone 方法。</p>
 *
 * @author jl
 * @version v1.0.0.1。
 * @since JDK1.8。
 * <p>创建日期：2019/10/26 下午6:08。</p>
 *
 * 注：如果引用类型里面还包含很多引用类型，或者内层引用类型的类里面又包含引用类型，使用clone方法就会很麻烦
 */
public class Student1 implements Cloneable {

	private static final long serialVersionUID = -9111812742820430930L;
	private int age;
	private Address1 address;
	private Date birthday;
	private Integer grade;
	private List<String> list;

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Address1 getAddress() {
		return address;
	}

	public void setAddress(Address1 address) {
		this.address = address;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Integer getGrade() {
		return grade;
	}

	public void setGrade(Integer grade) {
		this.grade = grade;
	}

	public List<String> getList() {
		return list;
	}

	public void setList(List<String> list) {
		this.list = list;
	}

	@Override
	protected Student1 clone() {
		Student1 student = null;
		try {
			student = (Student1) super.clone();
			student.address = this.address.clone();
			student.list = (List<String>) ((ArrayList<String>) this.list).clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return student;
	}

	@Override
	public String toString() {
		return "Student{" +
				"age=" + age +
				", address=" + address.getAdd() +
				", birthday=" + birthday +
				", grade=" + grade +
				", list=" + list +
				'}';
	}
}
